project(Application)

add_executable(${PROJECT_NAME}
    main.cc
)

target_link_libraries(${PROJECT_NAME}
        PRIVATE Qt5::Gui
        PRIVATE Qt5::Widgets
        PRIVATE Ces
        PRIVATE glog::glog
)
add_dependencies(${PROJECT_NAME} Plugin-Gui)

include(CPack)
include(GNUInstallDirs)
include(InstallRequiredSystemLibraries)

if(DEFINED ENV{QTDIR})
    if(WIN32)
        if(EXISTS $ENV{QTDIR}/bin/windeployqt.exe)
            if(CMAKE_BUILD_TYPE MATCHES Release)
                set(BINARIES_TYPE --release)
                set(ARCHIVE_OUTPUT ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE})
            else()
                set(BINARIES_TYPE --debug)
                set(ARCHIVE_OUTPUT ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG})
            endif()

            add_custom_command(
                    TARGET Application POST_BUILD
                    COMMAND $ENV{QTDIR}/bin/windeployqt.exe
                    ${BINARIES_TYPE}
                    --compiler-runtime
                    --no-system-d3d-compiler
                    --no-angle
                    --no-webkit2
                    --no-quick-import
                    --no-translations
                    --dir
                    ${ARCHIVE_OUTPUT}
                    $<TARGET_FILE:${PROJECT_NAME}>
            )

        else()
            message("Unable to find executable ${QTDIR}/bin/windeployqt.")
        endif()
    endif()
else()
    message(FATAL_ERROR "{QTDIR} is not setting! Packages will not be created！")
endif()